package com.spring.learn.aop;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.lang.annotation.Annotation;
import java.util.Arrays;

@Component
@Aspect
public class LoggingAspect implements Order {


    /**
     * 定义切点
     */
    @Pointcut("execution(public * com.spring.learn.aop.ProductServiceImpl.*(..))")
    public void pointCut() {

    }


    /**
     * 前置通知
     * 执行方法前，记录参数信息
     * @param point
     */
    @Before(value = "pointCut()")
    public void before(JoinPoint point) {
        System.out.println("【记录日志】，准备执行方法:" + point.getSignature().getName()+",参数列表:"+ Arrays.toString(point.getArgs()));
    }


    @AfterReturning(value = "pointCut()",returning = "returnVal")
    public void afterReturning(JoinPoint point,Object returnVal) {
        System.out.println("【记录日志】,方法执行结束:" + point.getSignature().getName()+",返回值:"+ returnVal);
    }

    @Override
    public int value() {
        return 0;
    }

    @Override
    public Class<? extends Annotation> annotationType() {
        return null;
    }
}
